import api from './api'

// 搜索相关API
const searchAPI = {
  // 搜索商品
  searchProducts(keyword, params = {}) {
    return api.get('/search/products', {
      params: {
        keyword,
        page: params.page || 1,
        pageSize: params.pageSize || 12,
        categoryId: params.categoryId,
        brandId: params.brandId,
        minPrice: params.minPrice,
        maxPrice: params.maxPrice,
        sortBy: params.sortBy,
        filters: params.filters,
        ...params
      }
    })
  },
  
  // 获取搜索建议
  getSearchSuggestions(keyword) {
    return api.get('/search/suggestions', {
      params: { keyword }
    })
  },
  
  // 获取热门搜索词
  getHotSearchTerms(params = {}) {
    return api.get('/search/hot-terms', {
      params: {
        limit: params.limit || 10,
        ...params
      }
    })
  },
  
  // 获取搜索历史
  getSearchHistory(params = {}) {
    return api.get('/search/history', {
      params: {
        limit: params.limit || 20,
        ...params
      }
    })
  },
  
  // 清除搜索历史
  clearSearchHistory() {
    return api.delete('/search/history/clear')
  },
  
  // 删除单个搜索历史
  deleteSearchHistory(id) {
    return api.delete(`/search/history/${id}`)
  },
  
  // 搜索商品分类
  searchCategories(keyword, params = {}) {
    return api.get('/search/categories', {
      params: {
        keyword,
        ...params
      }
    })
  },
  
  // 搜索品牌
  searchBrands(keyword, params = {}) {
    return api.get('/search/brands', {
      params: {
        keyword,
        ...params
      }
    })
  },
  
  // 获取搜索统计数据
  getSearchStatistics(keyword) {
    return api.get('/search/statistics', {
      params: { keyword }
    })
  }
}

export default searchAPI